/**
 * 
 */
package com.lanswon.controller.app;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lanswon.common.constants.Constants;
import com.lanswon.common.enums.MessageType;
import com.lanswon.common.enums.UserType;
import com.lanswon.common.enums.VerifyTypes;
import com.lanswon.common.util.StringUtil;
import com.lanswon.common.util.TokenProccessor;
import com.lanswon.entity.UserVO;
import com.lanswon.entity.Verification;
import com.lanswon.qzsmk.service.commonservice.CardProductListVo;
import com.lanswon.service.AdminService;
import com.lanswon.service.MobileService;
import com.lanswon.service.UserCardService;
import com.lanswon.service.UserService;
import com.lanswon.service.VerificationService;

import net.sf.json.JSONObject;

/**
 * 
 * @ClassName: AppUserController.java
 * @Description: 该类的功能描述
 *
 * @version: v1.0.0
 * @author: zm
 * @date: 2018年5月19日 上午9:51:57
 *
 */
@Controller
@RequestMapping("app/user")
public class AppUserController {

	@Autowired
	UserService userService;
	@Autowired
	AdminService adminService;
	@Autowired
	private MobileService mobileService;
	@Autowired
	private VerificationService verificationService;
	@Autowired
	private UserCardService userCardService;

	/**
	 * zj
	 * 
	 * @Title: delUserInfo
	 * @Description: TODO(用户信息注销)
	 * @param @param
	 *            userPhone
	 * @param @param
	 *            verifyCode
	 * @param @return
	 *
	 */
	@RequestMapping("/delUserInfo")
	@ResponseBody
	public Map<String, Object> delUserInfo(HttpServletRequest request, String token, String userPhone,
			String verifyCode, Long userId) {
		Map<String, Object> viewMap = new HashMap<>();
		try {
			// 登陆校验
			if (userId == null || StringUtil.isEmpty(token)) {
				viewMap.put("code", 1);
				viewMap.put("message", "用户未登录");
				return viewMap;
			}
			UserVO user = userService.getUser(userId);
			if (user == null) {
				viewMap.put("code", 2);
				viewMap.put("message", "用户不存在或未登录");
				return viewMap;
			}
			Verification verify = verificationService.findVerificationByPhone(user.getMobile());
			if (verify == null || !verify.getToken().equals(token)) {
				viewMap.put("code", 3);
				viewMap.put("message", "验证过期，请重新登录");
				return viewMap;
			}
			if (!verifyCode.equals(verify.getVerifycode())) {
				viewMap.put("code", 6);
				viewMap.put("message", "验证码不正确");
				return viewMap;
			}
			UserVO userVO = userService.findUserByMobile(userPhone);
			if (userVO == null) {
				viewMap.put("code", 4);
				viewMap.put("message", "用户不存在");
				return viewMap;
			}
			userService.delUserInfo(userPhone);
			viewMap.put("code", 0);
			viewMap.put("message", "删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 99);
			viewMap.put("message", "删除失败");
		}
		return viewMap;
	}

	@RequestMapping("/checkUserName")
	@ResponseBody
	public Map<String, Object> checkUserName(String userName) {
		return userService.checkUserName(userName);
	}

	@RequestMapping("/checkEmail")
	@ResponseBody
	public Map<String, Object> checkEmail(String email) {
		return userService.checkEmail(email);
	}

	/**
	 * 发送手机验证码
	 * 
	 * @param phone
	 * @param request
	 * @return
	 */
	@RequestMapping("/sendPhoneVerifyCode") // checkPhone
	@ResponseBody
	public Map<String, Object> sendPhoneVerifyCode(String phone, String verifyType, HttpServletRequest request) {
		Map<String, Object> viewMap = new HashMap<>();
		try {
			// userService.checkPhone(phone)
			// 参数验证
			if (StringUtil.isEmpty(phone) || !StringUtil.isMobile(phone)) {
				viewMap.put("code", 1);
				viewMap.put("message", "请正确填写手机号");
				return viewMap;
			}
			if (StringUtil.isEmpty(verifyType)) {
				verifyType = "4";
			}
			String smsTemplate = "";
			if (VerifyTypes.REGISTER.getCode().equals(verifyType)) {// 注册
				smsTemplate = Constants.SMS_USER_REGISTER;
			} else if (VerifyTypes.MODIFY_PSWD.getCode().equals(verifyType)) {// 修改密码
				smsTemplate = Constants.SMS_UPDATEP_ASSWORD;
			} else if (VerifyTypes.FIND_PSWD.getCode().equals(verifyType)) {// 忘记密码
				smsTemplate = Constants.SMS_UPDATEP_ASSWORD;
			} else if (VerifyTypes.DEL_USER.getCode().equals(verifyType)) {
				smsTemplate = Constants.SMS_UPDATE_INFO;
			} else {
				smsTemplate = Constants.SMS_UPDATE_INFO;
			}
			// 生成验证码
			String verifyCode = StringUtil.makePhoneCode(phone);
			Map<String, Object> verifyCodeMap = new HashMap<String, Object>();
			verifyCodeMap.put("code", verifyCode);
			mobileService.sendSmsVerificationCode(phone, JSONObject.fromObject(verifyCodeMap).toString(), smsTemplate);
			// session存储验证码
			HttpSession session = request.getSession();
			long verifyTime = new Date().getTime();
			session.setAttribute("verifyCode", verifyCode);
			session.setAttribute("isVerifyCodeExpired", verifyTime);
			// 存储验证码
			// UserVO user = userService.findUserByMobile(phone);
			Verification verify = verificationService.findVerificationByPhone(phone);
			if (verify == null) {
				verify = new Verification();
				verify.setPhone(phone);
				verify.setVerifycode(verifyCode);
				verify.setVerifytime(verifyTime);
				verificationService.addVerification(verify);
			} else {
				verify.setVerifycode(verifyCode);
				verify.setVerifytime(verifyTime);
				verificationService.updateVerification(verify);
			}

			viewMap.put("code", 0);
			viewMap.put("message", "请求成功");
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 99);
			viewMap.put("message", e.getMessage());
		}
		return viewMap;
	}

	/**
	 * @Title: doRegister
	 * @Description: TODO(注册)
	 *
	 */
	@RequestMapping("/register")
	@ResponseBody
	public Map<String, Object> doRegister(HttpServletRequest request, String verifyCode, String password,
			String confirmPassword, String phone) throws IOException {
		Map<String, Object> viewMap = new HashMap<>();
		try {
			HttpSession session = request.getSession();
			// 参数验证
			if (StringUtil.isEmpty(password) || StringUtil.isEmpty(confirmPassword) || StringUtil.isEmpty(phone)
					|| StringUtil.isEmpty(verifyCode) || !StringUtil.isMobile(phone)) {
				viewMap.put("code", 1);
				viewMap.put("message", "参数异常");
				return viewMap;
			}
			if (!password.equals(confirmPassword)) {
				viewMap.put("code", 2);
				viewMap.put("message", "密码与确认密码不一致");
				return viewMap;
			}
			if (!StringUtil.containAlphanumeric(password) && password.length() < 8) {
				viewMap.put("code", 4);
				viewMap.put("message", "密码必须包含字母和数字并且长度不能小于8");
				return viewMap;
			}
			Verification verification = verificationService.findVerificationByPhone(phone);
			Long time = new Date().getTime();
			if ((time.longValue() - verification.getVerifytime().longValue()) / 1000 > 60) {
				viewMap.put("code", 4);
				viewMap.put("message", "验证码过期");
				return viewMap;
			}
			if (StringUtil.isEmpty(verification.getVerifycode()) || !verifyCode.equals(verification.getVerifycode())) {
				viewMap.put("code", 3);
				viewMap.put("message", "验证码错误");
				return viewMap;
			}

			UserVO userVO = userService.findUserByMobile(phone);
			if (userVO != null) {
				viewMap.put("code", 4);
				viewMap.put("message", "该用户已注册");
				return viewMap;
			}
			UserVO user = new UserVO();
			user.setMobile(phone);
			user.setUserName(phone);
			user.setPassword(StringUtil.md5(password));
			user.setUserType(UserType.UT002.getCode().byteValue());
			userService.addUser(user);
			viewMap.put("code", 0);
			viewMap.put("message", "请求成功");
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 99);
			viewMap.put("message", e.getMessage());
		}
		// userService.updateTokenById(userService.doRegister(request));
		return viewMap;
	}

	@SuppressWarnings("unused")
	@RequestMapping("/login") // loginCheck
	@ResponseBody
	public Map<String, Object> login(HttpServletRequest request, String phone, String password) throws IOException {
		Map<String, Object> viewMap = new HashMap<>();
		try {
			if (StringUtil.isEmpty(phone) || StringUtil.isEmpty(password) || !StringUtil.isMobile(phone)) {
				viewMap.put("code", 1);
				viewMap.put("message", "用户名密码不正确");
				return viewMap;
			}
			UserVO user = userService.findUserByMobile(phone);
			if (user == null) {
				viewMap.put("code", 2);
				viewMap.put("message", "该用户还未注册");
				return viewMap;
			}
			String md5password = StringUtil.md5(password);
			if (!md5password.equals(user.getPassword())) {
				viewMap.put("code", 3);
				viewMap.put("message", "密码不正确");
				return viewMap;
			}
			request.getSession().setAttribute("userId", user.getUserId());
			String apptoken = TokenProccessor.getInstance().makeToken();
			Map<String, Object> data = new HashMap<>();
			Class<? extends UserVO> clazz = user.getClass();
			Field[] fields = clazz.getDeclaredFields();
			for (Field field : fields) {
				field.setAccessible(true);
				data.put(field.getName(), field.get(user));
			}
			data.put("token", apptoken);
			// 更新token
			Verification verify = verificationService.findVerificationByPhone(phone);
			if (verify == null) {
				verify = new Verification();
				verify.setPhone(phone);
				verify.setToken(apptoken);
				verificationService.addVerification(verify);
			} else {
				verify.setToken(apptoken);
				verificationService.updateVerificationByPhone(verify);
			}

			// request.getSession().setAttribute("apptoken", apptoken);
			viewMap.put("code", 0);
			viewMap.put("message", "登录成功");
			viewMap.put("data", data);
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 99);
			viewMap.put("message", "登录失败");
		}
		return viewMap;
	}

	/**
	 * @Title: updateUserInfo
	 * @Description: TODO(修改个人信息)
	 * @param @param
	 *            request
	 * @param @param
	 *            token
	 * @param @param
	 *            realName
	 * @param @param
	 *            idNum
	 * @param @param
	 *            birthday
	 * @param @param
	 *            verifyCode
	 * @param @return
	 *
	 */
	@RequestMapping("/updateUserInfo")
	@ResponseBody
	public Map<String, Object> updateUserInfo(HttpServletRequest request, String token, String realName, String idNum,
			String birthday, String verifyCode, Long userId, String email) {
		Map<String, Object> viewMap = new HashMap<>();
		try {
			if (StringUtil.isEmpty(token) || StringUtil.isEmpty(realName) || StringUtil.isEmpty(idNum)
					|| StringUtil.isEmpty(birthday) || StringUtil.isEmpty(verifyCode) || userId == null) {
				viewMap.put("code", 1);
				viewMap.put("message", "参数异常");
				return viewMap;
			}
			if (!StringUtil.isIdNum(idNum)) {
				viewMap.put("code", 2);
				viewMap.put("message", "身份证填写错误");
				return viewMap;
			}
			if (!StringUtil.isDate(birthday)) {
				viewMap.put("code", 3);
				viewMap.put("message", "生日填写不正确");
				return viewMap;
			}
			UserVO userVO = userService.getUser(userId);
			if (userVO == null) {
				viewMap.put("code", 4);
				viewMap.put("message", "用户不存在");
				return viewMap;
			}

			// 验证token
			Verification verify = verificationService.findVerificationByPhone(userVO.getMobile());
			if (verify == null || !verify.getToken().equals(token)) {
				viewMap.put("code", 5);
				viewMap.put("message", "验证过期，请重新登录");
				return viewMap;
			}
			if (!verifyCode.equals(verify.getVerifycode())) {
				viewMap.put("code", 6);
				viewMap.put("message", "验证码不正确");
				return viewMap;
			}
			UserVO userVO2 = userService.getUserByIdNo(idNum);
			if (userVO2 != null) {
				viewMap.put("code", 7);
				viewMap.put("message", "该证件号已被绑定");
				return viewMap;
			}

			UserVO user = new UserVO();
			user.setUserId(userId);
			user.setRealName(realName);
			user.setIdNum(idNum);
			user.setPapertype("00");
			user.setPaperno(idNum);
			user.setEmail(email);
			user.setBirthday(birthday);
			userService.updateUserInfo(user);
			Map<Object, Object> dataMap = new HashMap<>();
			dataMap.put("realName", realName);
			dataMap.put("idNum", idNum);
			dataMap.put("birthday", birthday);
			dataMap.put("email", email);
			viewMap.put("data", dataMap);
			viewMap.put("code", 0);
			viewMap.put("message", "修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 99);
			viewMap.put("message", "操作错误");
		}

		// adminService.withdraw(request);
		return viewMap;

	}

	@RequestMapping("/withdraw")
	@ResponseBody
	public Map<String, Object> withdraw(HttpServletRequest request) {
		return adminService.withdraw(request);

	}

	/**
	 * @Title: changeValidate
	 * @Description: TODO(九、忘记密码)
	 */
	@RequestMapping("/forgetPassword")
	@ResponseBody
	public Map<String, Object> forgetPassword(HttpServletRequest request, String phone, String verifyCode,
			String newPassword) throws IOException {
		Map<String, Object> viewMap = new HashMap<>();

		try {
			if (StringUtil.isEmpty(phone) || StringUtil.isEmpty(verifyCode) || StringUtil.isEmpty(newPassword)) {
				viewMap.put("code", 1);
				viewMap.put("message", "参数不能为空");
				return viewMap;
			}
			Verification verification = verificationService.findVerificationByPhone(phone);
			Long time = new Date().getTime();
			if ((time.longValue() - verification.getVerifytime().longValue()) / 1000 > 60) {
				viewMap.put("code", 4);
				viewMap.put("message", "验证码过期");
				return viewMap;
			}
			if (StringUtil.isEmpty(verification.getVerifycode()) || !verifyCode.equals(verification.getVerifycode())) {
				viewMap.put("code", 3);
				viewMap.put("message", "验证码错误");
				return viewMap;
			}
			userService.forgetPassword(phone, newPassword);
			viewMap.put("code", 0);
			viewMap.put("message", "修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 99);
			viewMap.put("message", "操作失败");
		}
		return viewMap;
	}

	@RequestMapping("/bind")
	@ResponseBody
	public Map<String, Object> bind(HttpServletRequest request, String token, String paperType, String paperNo,
			Long userId, String cardType, @RequestParam(value = "cardNos[]") String[] cardNos)
			throws UnsupportedEncodingException {
		Map<String, Object> viewMap = new HashMap<>();
		try {
			// 传参校验
			if (StringUtil.isEmpty(token) || StringUtil.isEmpty(paperType) || StringUtil.isEmpty(paperNo)
					|| userId == null || cardNos == null || cardNos.length <= 0) {
				viewMap.put("code", 1);
				viewMap.put("message", "证件信息或卡信息不能为空");
				return viewMap;
			}
			UserVO user = userService.getUser(userId);
			if (user == null) {
				viewMap.put("code", 2);
				viewMap.put("message", "用户不存在或未登录");
				return viewMap;
			}
			Verification verify = verificationService.findVerificationByPhone(user.getMobile());
			if (verify == null || !verify.getToken().equals(token)) {
				viewMap.put("code", 3);
				viewMap.put("message", "验证过期，请重新登录");
				return viewMap;
			}
			if (!StringUtil.isEmpty(user.getPaperno()) && !StringUtil.isEmpty(user.getPapertype())) {
				if (user.getPaperno().equals(paperNo) && user.getPapertype().equals(paperType)) {
				} else {
					viewMap.put("code", 4);
					viewMap.put("message", "证件号和证件类型填写错误");
					return viewMap;
				}
			} else {
				if (user.getIdNum().equals(paperNo)) {
					user.setPaperno(paperNo);
					user.setPapertype(paperType);
				} else {
					viewMap.put("code", 5);
					viewMap.put("message", "证件信息与用户验证信息不相同");
					return viewMap;
				}
			}
			viewMap = userService.bind(user, cardNos);
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 99);
			viewMap.put("message", "绑定失败");
		}

		return viewMap;
	}

	// 21.已绑定卡
	@RequestMapping("isCardBinded")
	@ResponseBody
	public JSONObject isCardBinded(Long userId, String token, Integer isBinded, String paperNo, String paperType) {

		JSONObject jsonObject = new JSONObject();
		try {
			// 传参校验
			if (userId == null || StringUtil.isEmpty(token) || StringUtil.isEmpty(paperNo)
					|| StringUtil.isEmpty(paperType) || isBinded == null) {
				jsonObject.put("code", 1);
				jsonObject.put("message", "参数为空");
				return jsonObject;
			}
			UserVO user = userService.getUser(userId);
			if (user == null) {
				jsonObject.put("code", 2);
				jsonObject.put("message", "用户不存在或未登录");
				return jsonObject;
			}
			if(!paperNo.equals(user.getPaperno())||!paperType.equals(user.getPapertype())){
				jsonObject.put("code", 3);
				jsonObject.put("message", "证件号或证件类型不正确");
				return jsonObject;
			}
			Verification verify = verificationService.findVerificationByPhone(user.getMobile());
			if (verify == null || !verify.getToken().equals(token)) {
				jsonObject.put("code", 3);
				jsonObject.put("message", "验证过期，请重新登录");
				return jsonObject;
			}
			List<CardProductListVo> ucList = userCardService.isCardBinded(user, isBinded, paperNo, paperType);

			jsonObject.put("code", 0);
			jsonObject.put("message", "请求成功");
			jsonObject.put("data", ucList);
		} catch (Exception e) {
			e.printStackTrace();
			jsonObject.put("code", 99);
			jsonObject.put("message", e.getMessage());
		}
		return jsonObject;
	}

	/**
	 * @Title: changePassword
	 * @Description: TODO(修改密码)
	 *
	 */
	@RequestMapping("/changePassword")
	@ResponseBody
	public Map<String, Object> changePassword(HttpServletRequest request, String token, String oldPassword,
			String newPassword, String verifyCode, Long userId) throws IOException {
		Map<String, Object> viewMap = new HashMap<>();
		JSONObject jsonObject = new JSONObject();
		try {
			if (userId == null) {
				jsonObject.put("code", 1);
				jsonObject.put("message", "参数为空");
				return jsonObject;
			}
			UserVO user = userService.getUser(userId);
			if (user == null) {
				jsonObject.put("code", 2);
				jsonObject.put("message", "用户不存在或未登录");
				return jsonObject;
			}
			// 传参校验
			if (StringUtil.isEmpty(token) || StringUtil.isEmpty(oldPassword) || StringUtil.isEmpty(newPassword)
					|| StringUtil.isEmpty(verifyCode)) {
				viewMap.put("code", 2);
				viewMap.put("message", MessageType.MT_SR_3);
				return viewMap;
			}

			Verification verify = verificationService.findVerificationByPhone(user.getMobile());
			if (verify == null || !verify.getToken().equals(token)) {
				jsonObject.put("code", 3);
				jsonObject.put("message", "验证过期，请重新登录");
				return jsonObject;
			}
			if (!verifyCode.equals(verify.getVerifycode())) {
				viewMap.put("code", 3);
				viewMap.put("message", "验证码错误");
				return viewMap;
			}
			Long time = new Date().getTime();
			if ((time.longValue() - verify.getVerifytime().longValue()) / 1000 > 60) {
				viewMap.put("code", 4);
				viewMap.put("message", "验证码过期");
				return viewMap;
			}

			viewMap = userService.changePassword(userId, oldPassword, newPassword);
			viewMap.put("code", 0);
			viewMap.put("message", "修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 99);
			viewMap.put("message", "操作失败");
		}
		return viewMap;
	}

	/**
	 * @Title: changeEmail
	 * @Description: TODO(修改邮箱)
	 * @param @param
	 *            request
	 * @param @param
	 *            token
	 * @param @param
	 *            oldEmail
	 * @param @param
	 *            newEmail
	 * @param @return
	 * @param @throws
	 *            IOException
	 *
	 */
	@RequestMapping("/changeEmail")
	@ResponseBody
	public Map<String, Object> changeEmail(HttpServletRequest request, String token, String oldEmail, String newEmail,
			Long userId) throws IOException {
		Map<String, Object> viewMap = new HashMap<>();
		try {
			// 传参校验
			if (userId == null || StringUtil.isEmpty(token) || StringUtil.isEmpty(newEmail)) {
				viewMap.put("code", 1);
				viewMap.put("message", "参数为空");
				return viewMap;
			}
			if (!StringUtil.isEmail(newEmail)) {
				viewMap.put("code", 2);
				viewMap.put("message", "邮箱格式不正确或不合格");
				return viewMap;
			}
			UserVO user = userService.getUser(userId);
			if (user == null) {
				viewMap.put("code", 3);
				viewMap.put("message", "用户不存在或未登录");
				return viewMap;
			}
			Verification verify = verificationService.findVerificationByPhone(user.getMobile());
			if (verify == null || !verify.getToken().equals(token)) {
				viewMap.put("code", 4);
				viewMap.put("message", "验证过期，请重新登录");
				return viewMap;
			}
			if (StringUtil.isEmpty(user.getEmail()) && StringUtil.isEmpty(oldEmail)) {
			} else if (!oldEmail.equals(user.getEmail() == null ? "" : user.getEmail())) {
				viewMap.put("code", 5);
				viewMap.put("message", "原邮箱填写不正确");
				return viewMap;
			}
			user.setEmail(newEmail);
			userService.updateUserInfo(user);
			Map<String, Object> dataMap = new HashMap<>();
			dataMap.put("email", newEmail);
			viewMap.put("code", 0);
			viewMap.put("message", "修改成功");
			viewMap.put("data", dataMap);
		} catch (Exception e) {
			e.printStackTrace();
			viewMap.put("code", 99);
			viewMap.put("message", "修改失败");
		}

		// userService.changeEmail(userId, oldEmail, newEmail);
		return viewMap;
	}

	@SuppressWarnings("unchecked")
	@RequestMapping("/changePhone")
	@ResponseBody
	public Map<String, Object> changePhone(HttpServletRequest request, String token, String oldPhone, String newPhone)
			throws IOException {
		request.setCharacterEncoding("utf-8");
		JSONObject jsonObject = new JSONObject();
		Long userId = (Long) request.getSession().getAttribute("userId");
		// 登陆校验
		if (userId == null) {
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT012);
			return jsonObject;
		}
		// 传参校验
		if (StringUtil.isEmpty(token) || StringUtil.isEmpty(oldPhone) || StringUtil.isEmpty(newPhone)) {
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT_SR_4);
			return jsonObject;
		}
		String apptoken = (String) request.getSession().getAttribute("apptoken");
		if (!apptoken.equals(token)) {
			jsonObject.put("code", 3);
			jsonObject.put("message", "验证过期，请重新登录");
			return jsonObject;
		}

		return userService.changePhone(userId, oldPhone, newPhone);
	}

	@SuppressWarnings("unchecked")
	@RequestMapping("/changePhoneValidate")
	@ResponseBody
	public Map<String, Object> changePhoneValidate(HttpServletRequest request, String token, String verifyCode)
			throws IOException {
		request.setCharacterEncoding("utf-8");
		JSONObject jsonObject = new JSONObject();
		Long userId = (Long) request.getSession().getAttribute("userId");
		// 登陆校验
		if (userId == null) {
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT012);
			return jsonObject;
		}
		// 传参校验
		if (StringUtil.isEmpty(token) || StringUtil.isEmpty(verifyCode)) {
			jsonObject.put("code", 1);
			jsonObject.put("message", MessageType.MT_SR_6);
			return jsonObject;
		}
		String apptoken = (String) request.getSession().getAttribute("apptoken");
		if (!apptoken.equals(token)) {
			jsonObject.put("code", 3);
			jsonObject.put("message", "验证过期，请重新登录");
			return jsonObject;
		}

		return userService.changePhoneValidate(verifyCode, userId, request);
	}

	@RequestMapping("/getUserInfo")
	@ResponseBody
	public Map<String, Object> getUserInfo(HttpServletRequest request, Long userId, String token) throws IOException {
		Map<String, Object> viewMap = new HashMap<>();
		// 登陆校验
		if (userId == null) {
			viewMap.put("code", 1);
			viewMap.put("message", "用户尚未登录");
			return viewMap;
		}
		UserVO user = userService.getUser(userId);
		if (user == null) {
			viewMap.put("code", 2);http://localhost:8080/qzsmkweb/app/user/getUserInfo.do?userId=263&token=Lmsi7++QM3LH4H0zyE2BdA==
			viewMap.put("message", "用户不存在或未登录");
			return viewMap;
		}
		Verification verify = verificationService.findVerificationByPhone(user.getMobile());
		if (verify == null || !verify.getToken().equals(token)) {
			viewMap.put("code", 3);
			viewMap.put("message", "验证过期，请重新登录");
			return viewMap;
		}
		viewMap.put("code", 0);
		viewMap.put("message", "获取成功");
		viewMap.put("data", user);

		return viewMap;

	}

}
